<?php
/**
*
* @package acp
* @version $Id: acp_lexportal.php 0 18 jan 2009 18:53:10 Alexander de Jong $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* @package acp
*/
class acp_lexportal
{
	var $u_action;
	
	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $cache;
		global $phpbb_root_path, $phpbb_admin_path, $phpEx;
		
		// $user->add_lang('acp/lexportal/lexportal');
		$user->add_lang('install');
		
		switch($mode)
		{
			case 'lexportal_version':
				$this->_lexportal_version();
			break;
			
			case 'lexportal_config':
				$this->_lexportal_config($id, $mode);
			break;
		}
	}
	
	function _lexportal_version()
	{
		global $db, $template;
		
		// version check
		$sql = "SELECT * FROM " . LEXPORTAL_TABLE;
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult();
		
		$version_file = (defined('LEXPORTAL_QA')) ? '10x_qa.txt' : '10x.txt';
		
		$errstr = '';
		$errno = '';
		
		$file_content = get_remote_file('versions.dexora.net', '/lexportal', $version_file, $errstr, $errno);
		
		// Get the lines.
		$lines = explode("\n", $file_content);
		
		$info = parse_cfg_file($file_content, $lines);
		
		// Get the current version
		$current_version = explode('-', $row['version']);
		$current_version = $current_version[0];
		
		// Get the latest version
		$latest_version = explode('-', $info['version']);
		$latest_version = $latest_version[0];
		
		// Get the current status protocol
		$current_status_protocol = explode('-', $row['version']);
		$current_status_protocol = $current_status_protocol[1];
		
		// Get the latest status protocol
		$latest_status_protocol = explode('-', $info['version']);
		$latest_status_protocol = $latest_status_protocol[1];
		
		$up_to_date = (version_compare($current_version, $latest_version, '<')) ? false : true;
		
		if($up_to_date == true)
		{
			$up_to_date = ($current_status_protocol == $latest_status_protocol) ? true : false;
		}
		
		if(defined('LEXPORTAL_QA'))
		{
			$current_revision = $row['revision'];
			$latest_revision = $info['revision'];
			
			if($up_to_date == true)
			{
				$up_to_date = ($current_revision == $latest_revision) ? true : false;
			}
			
			$template->assign_vars(array(
				'IN_QA'				=> true,
				'UP_TO_DATE'		=> $up_to_date,
				'CURRENT_VERSION'	=> $current_version . '-' . $current_status_protocol,
				'LATEST_VERSION'	=> $latest_version . '-' . $latest_status_protocol,
				'CURRENT_REVISION'	=> $current_revision,
				'LATEST_REVISION'	=> $latest_revision,
				'RELEASE_DATE'		=> $info['release_date'],
				'QA_INFO_URL'		=> $info['info'],
				'UPDATE_URL'		=> $info['update_url'],
				'QA_WEB'			=> $info['qa_web_url'],
				'PROJECT_URL'		=> $info['project_url'],
				'WEB_URL'			=> $info['web_url'],
			));
		}
		else
		{
			$template->assign_vars(array(
				'IN_QA'				=> false,
				'UP_TO_DATE'		=> $up_to_date,
				'CURRENT_VERSION'	=> $current_version . '-' . $current_status_protocol,
				'LATEST_VERSION'	=> $latest_version . '-' . $latest_status_protocol,
				'RELEASE_DATE'		=> $info['release_date'],
				'SUPPORT_URL'		=> $info['support_url'],
				'UPDATE_URL'		=> $info['update_url'],
				'CHANGELOG_URL'		=> $info['changelog_url'],
				'MOD_URL'			=> $info['mod_url'],
				'STYLE_URL'			=> $info['style_url'],
				'WEB_URL'			=> $info['web_url'],
			));
		}
		
		$this->page_title = 'Versie check';
		$this->tpl_name = "acp_lexportal";
	}
	
	function _lexportal_config($id, $mode)
	{
		trigger_error('This is not yet created.', E_USER_WARNING);
	}
}

?>